/*
 * ReserveTable.cpp
 *
 *  Created on: 2009-8-27
 *      Author: ws
 */

#include "ReserveTable.hpp"
#include"UsageFU.hpp"
#include"operation_usage.hpp"

ReserveTable::ReserveTable()
{
	for(int i = 0; i < FT_BUS_T+1; i++ )
	{
		for(int j = 0; j < CORE_X; j++)
		{
			private_reserver[i][j] = Numof_Resource((enum _Function_Type) i);
		}
	}
	for(int i = FT_BUS_T+1; i < FT_end;i++)
	{
		public_reserver[i] = Numof_Resource((enum _Function_Type) i);
	}
}

ReserveTable::~ReserveTable() {
}

bool ReserveTable::submit_option(enum Core c, enum _Function_Type ft)
{
	int & x = _get_fu_left_num(c, ft);
	x--;
	if(x >= 0)
		return true;
	else
		return false;
}

ReserveTable ReserveTable::operator =(const ReserveTable & rev)const
{
	return ReserveTable(rev);
}


int & ReserveTable::_get_fu_left_num(enum Core c, enum _Function_Type ft)
{
	(const ReserveTable*)(this)->_get_fu_left_num(c, ft);
}


const int& ReserveTable::_get_fu_left_num(enum Core c, enum _Function_Type ft)const
{
	assert(ft >= 0);
	//private or no
	if( ft < FT_BUS_T + 1 && ft >= 0)
	{
		return private_reserver[ft][c];
	}
	if( ft < FT_end && ft > FT_BUS_T)
	{
		return public_reserver[ft] ;
	}
}

